var CusNameSpace = window.CusNameSpace || {};
/*
 Class UpdateTopState
 Function  Top Refrush
 */
//程序模块
CusNameSpace.CusPageManualMode = function () {
    this.name = 'CusPageManualMode';
};

CusNameSpace.CusPageManualMode.prototype.onInitData = function () {


};
CusNameSpace.CusPageManualMode.prototype.pressKeysControlStop = function (e) {
    
    var windowIsShow = getVisibilityState();

    //浏览器隐藏时停止发送
    if (windowIsShow === "visibilityState")
    {

    } else
    {
        stopRockerManualTimer();
        return false;
    }
    
    var targetElement = $(e.target);
    var targetId = targetElement.attr("id");
    //手动按钮样式
    $("#" + targetId).css("border", "");


    if (targetId === "id_content_manual_window_bt_forward")
    {
        /* 前 */
        window.objGlobalManage.objCusProtocol.func_manual_stop();
    } else if (targetId === "id_content_manual_window_bt_back")
    {
        /* 后 */
        window.objGlobalManage.objCusProtocol.func_manual_stop();
    } else if (targetId === "id_content_manual_window_bt_left")
    {
        /*左*/

       window.objGlobalManage.objCusProtocol.func_manual_stop();
    } else if (targetId === "id_content_manual_window_bt_right")
    {
        /*右*/
        window.objGlobalManage.objCusProtocol.func_manual_stop();
    } else if (targetId === "id_content_manual_window_bt_turnleft")
    {
        /*左转*/
        /* 前 */
        window.objGlobalManage.objCusProtocol.func_manual_stop();
    } else if (targetId === "id_content_manual_window_bt_turnright")
    {
        /*右转*/
       window.objGlobalManage.objCusProtocol.func_manual_stop();
    }
};
CusNameSpace.CusPageManualMode.prototype.pressKeysControlRun = function (e) {

    var targetElement = $(e.target);
    var targetId = targetElement.attr("id");
    /* 停止运行 */
    var windowIsShow = getVisibilityState();

    //浏览器隐藏时停止发送
    if (windowIsShow === "visibilityState")
    {

    } else
    {
        stopManualTimer(e);
        return false;
    }


    //如果伺服关闭就提示开启
    if( (window.objGlobalManage.objCusUpdateTopState.variable_state_mode !== enumTypeMode.kModeT1) 
            && (window.objGlobalManage.objCusUpdateTopState.variable_state_mode !== enumTypeMode.kModeT2) )
    {
        window.objGlobalManage.tipsManualMustBeT1T2 = 1;
        $("#top_right_state_modle").trigger("click");
        return false;
    }
    //如果伺服关闭就提示开启
    if(window.objGlobalManage.objCusUpdateTopState.variable_state_servo === enumTypeServo.kServoClose)
    {
        $("#top_right_state_servo").trigger("click");
        return false;
    }

    //手动按钮样式添加边框
    $("#" + targetId).css("border", "solid 2px #3d4e60");
    if (targetId === "id_content_manual_window_bt_forward")
    {
        /* 前 */
        var mx = 1 * window.objGlobalManage.objCusUpdateTopState.variable_local_manual_v / 100.0;
        var my = 0.0;
        var mr = 0.0;
        window.objGlobalManage.objCusProtocol.func_manual_move(mx,my,mr);
        
    } else if (targetId === "id_content_manual_window_bt_back")
    {
        /*后 */

        var mx = -1 * window.objGlobalManage.objCusUpdateTopState.variable_local_manual_v / 100.0;
        var my = 0.0;
        var mr = 0.0;
        window.objGlobalManage.objCusProtocol.func_manual_move(mx,my,mr);
        
    } else if (targetId === "id_content_manual_window_bt_left")
    {
        /*左*/       
        var mx = 0.0;
        var my = -1 * window.objGlobalManage.objCusUpdateTopState.variable_local_manual_v / 100.0;
        var mr = 0.0;
        window.objGlobalManage.objCusProtocol.func_manual_move(mx,my,mr);
        
    } else if (targetId === "id_content_manual_window_bt_right")
    {
        /*右*/       
        var mx = 0.0;
        var my = 1 * window.objGlobalManage.objCusUpdateTopState.variable_local_manual_v / 100.0;
        var mr = 0.0;
        window.objGlobalManage.objCusProtocol.func_manual_move(mx,my,mr);
    } else if (targetId === "id_content_manual_window_bt_turnleft")
    {
        /*左转*/
        var mx = 0.0;
        var my = 0.0;
        var mr = 1 * window.objGlobalManage.objCusUpdateTopState.variable_local_manual_v / 100.0;
        window.objGlobalManage.objCusProtocol.func_manual_move(mx,my,mr);
    } else if (targetId === "id_content_manual_window_bt_turnright")
    {
        /*右转*/
        var mx = 0.0;
        var my = 0.0;
        var mr = -1 * window.objGlobalManage.objCusUpdateTopState.variable_local_manual_v / 100.0;
        window.objGlobalManage.objCusProtocol.func_manual_move(mx,my,mr);
    }

};
